package cn.aitstone.system.service.impl;

import cn.aitstone.basic.utils.PageList;
import cn.aitstone.org.domain.Employee;
import cn.aitstone.system.domain.DictionaryType;
import cn.aitstone.system.mapper.DictionaryDetailMapper;
import cn.aitstone.system.mapper.DictionaryTypeMapper;
import cn.aitstone.system.query.DictionaryTypeQuery;
import cn.aitstone.system.service.IDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
 * @Description: 数据字典类型实现类
 * @Author: Sheldon
 * @Version: 1.0
 * @Date:  2022/6/30 23:39
 */
@Service
// 只读事务
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class DictionaryTypeServiceImpl implements IDictionaryTypeService {
    @Autowired
    private DictionaryTypeMapper dictionaryTypeMapper;
    @Autowired
    private DictionaryDetailMapper dictionaryDetailMapper;
    @Override
    public List<DictionaryType> loadAll() {
        return dictionaryTypeMapper.loadAll();
    }

    @Override
    public DictionaryType loadById(Long id) {
        return dictionaryTypeMapper.loadById(id);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        DictionaryType dictionaryType = dictionaryTypeMapper.loadById(id);
        dictionaryDetailMapper.delchild(dictionaryType.getId());
        dictionaryTypeMapper.remove(id);
    }

    @Override
    @Transactional
    public void save(DictionaryType dictionaryType) {
        dictionaryTypeMapper.save(dictionaryType);
    }

    @Override
    @Transactional
    public void update(DictionaryType dictionaryType) {
        dictionaryTypeMapper.update(dictionaryType);
    }

    @Override
    public PageList<DictionaryType> queryData(DictionaryTypeQuery dictionaryTypeQuery) {
        List<DictionaryType> rows = dictionaryTypeMapper.queryData(dictionaryTypeQuery);
        Integer total = dictionaryTypeMapper.queryCount(dictionaryTypeQuery);
        return new PageList<>(total, rows);
    }

    @Override
    @Transactional
    public void batchdel(Long[] ids) {
        dictionaryTypeMapper.batchdel(ids);
    }
}
